package com.example.a79273.shandianban.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a79273.shandianban.R;
import com.example.a79273.shandianban.config.NetConfigYouRen;
import com.example.a79273.shandianban.model.YouRenBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * "有人"页面下面的Viewpager下的fragment的适配器
 */
public class YouRenRecyclerViewAdapter extends RecyclerView.Adapter<YouRenRecyclerViewAdapter.MyViewHolder> {

    private List<YouRenBean.DataBean.ListBean> mData;
    private LayoutInflater inflater;
    private Picasso picasso;


    public YouRenRecyclerViewAdapter(List<YouRenBean.DataBean.ListBean> data, Context context) {
        mData = data;
        inflater = LayoutInflater.from(context);
        picasso = Picasso.with(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = inflater.inflate(R.layout.item_item_youren, parent, false);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        YouRenBean.DataBean.ListBean bean = mData.get(position);
        picasso.load(NetConfigYouRen.ROOT_URL + bean.getAsrc()).into(holder.image_iv);
        holder.fans_tv.setText("" + bean.getFans());
        holder.designerName_tv.setText(bean.getName());
    }


    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder {

        private FrameLayout viewContainer;
        private ImageView image_iv;
        private TextView fans_tv, designerName_tv;

        public MyViewHolder(View itemView) {
            super(itemView);
            viewContainer = (FrameLayout) itemView.findViewById(R.id.fl_item_designer);
            image_iv = (ImageView) itemView.findViewById(R.id.iv_item_item_youren_image);
            fans_tv = (TextView) itemView.findViewById(R.id.tv_item_item_youren_fansCount);
            designerName_tv = (TextView) itemView.findViewById(R.id.tv_item_item_youren_designerName);

        }
    }


}
